function button_arrow_text_timer(){
	
	var ths = this;
	var config;
	var element;
	var element_id;
	
	var disabled;
	var hidden;
	var active;
	var ison;
	
	var onclick;
	ths.init = function($config){
				
		ths.config = $config;			
		
		if( $config.id ){
			ths.element_id = ths.config.id;
			ths.element = $("#"+ths.element_id);
		}
		else{
			ths.element = $config.element;
			ths.element_id = ths.element.id;
		}
		
		ths.ison=false;
		
		//States that can be applied by php
		ths.disabled=hasClass(ths.element, "disabled");
		ths.hidden=hasClass(ths.element, "hidden");
		
		//Clock
		ths.arrow = $(".arrow", ths.element)[0];
		ths.clock = new clock();
		ths.clock.init({element:$(".clock", ths.element)[0]});
		
		ths.element.onclick=function(){
			if( !ths.disabled && !ths.ison ){
				if( ths.onclick ) ths.onclick();
			}
		}
		
		if( ths.config.DEBUG ){
			alert(JSON.stringify({
				id:ths.element.id,
				class:ths.element.className,
				disabled:ths.disabled,	
				hidden:ths.hidden
			},
			null,5));
		}
	}
	ths.on = function(){
		if( !ths.ison ){
			ths.ison=true;
			addClass(ths.element, "on");
			addClass(ths.arrow, "hidden");
			ths.clock.on();
		}
	}
	ths.off = function(){
		if( ths.ison ){	
			ths.ison=false;	
			removeClass(ths.element, "on");	
			removeClass(ths.arrow, "hidden");
			ths.clock.off();
		}
	}
	ths.disable = function(){
		if( !ths.disabled ){
			ths.disabled=true;
			addClass(ths.element, "disabled");
		}
	}
	ths.enable = function(){
		if( ths.disabled ){
			ths.disabled=false;
			removeClass(ths.element, "disabled");
		}
	}
	ths.hide = function(){
		if( !ths.hidden ){
			ths.hidden=true;
			addClass(ths.element, "hidden");
		}
	}
	ths.show = function(){
		if( ths.hidden ){
			ths.hidden=false;
			removeClass(ths.element, "hidden");
		}
	}
	ths.dispose = function(){
		if( ths.inited ){
			ths.clock.dispose();
		}
		ths.inited=false;
	}
}

function rounded_button(){
	
	var ths = this;
	var config;
	var element;
	var element_id;

	var disabled;
	var hidden;
	var active;
	
	var onclick;
	
	ths.init = function($config){

		ths.config = $config;			
		
		if( $config.id ){
			ths.element_id = ths.config.id;
			ths.element = $("#"+ths.element_id);
		}
		else{
			ths.element = $config.element;
			ths.element_id = ths.element.id;
		}
		
		ths.disabled=hasClass(ths.element, "disabled");
		ths.hidden=hasClass(ths.element, "hidden");
		ths.active=hasClass(ths.element, "active");

		ths.element.onclick=function(){
			if( !ths.disabled && !ths.ison ){
				if( ths.onclick ) ths.onclick();
			}
		}
		
		if( ths.config.DEBUG ){
			alert(JSON.stringify({
				id:ths.element.id,
				class:ths.element.className,
				disabled:ths.disabled,	
				hidden:ths.hidden,
				active:ths.active,
			},
			null,5));
		}
	}
	ths.disable = function(){
		if( !ths.disabled ){
			ths.disabled=true;
			addClass(ths.element, "disabled");
		}
	}
	ths.enable = function(){
		if( ths.disabled ){
			ths.disabled=false;
			removeClass(ths.element, "disabled");
		}
	}
	ths.hide = function(){
		if( !ths.hidden ){
			ths.hidden=true;
			addClass(ths.element, "hidden");
		}
	}
	ths.show = function(){
		if( ths.hidden ){
			ths.hidden=false;
			removeClass(ths.element, "hidden");
		}
	}
	ths.dispose = function(){
		if( ths.inited ){
		}
		ths.inited=false;
	}
}

function input(){
	
	var ths = this;
	var config;
	var element;
	var element_id;

	var disabled;
	var hidden;
	var active;

	var onchange;
	var onenter;
	
	ths.init = function($config){
		
		ths.config = $config;			
		
		if( $config.id ){
			ths.element_id = ths.config.id;
			ths.element = $("#"+ths.element_id);
		}
		else{
			ths.element = $config.element;
			ths.element_id = ths.element.id;
		}
		
		ths.disabled=hasClass(ths.element, "disabled");
		ths.hidden=hasClass(ths.element, "hidden");
		
		ths.element.onclick=function(){
			if( !ths.disabled ){
				if( ths.onclick ) ths.onclick();
			}
		}

		ths.element.onkeyup = function(event){
			if( !ths.disabled ){
				//ENTER KEY
				if(event.keyCode==13||event.which==13){
					if(ths.onenter) ths.onenter(ths);
				} 
				if( ths.onchange ) ths.onchange(ths);
			}
		}
	}
	
	ths.get_value = function(){
		return ths.element.value;
	}
	
	ths.set_value = function($value){
		ths.element.value = $value;
	}
	
	ths.dispose = function(){
		if( ths.inited ){
		}
		ths.inited=false;
	}
}


function button_arrow_text(){
	var ths = this;
	var config;
	var enabled;
	var ison;
	var onclick;
	ths.init = function($config){
		ths.enabled=true;
		ths.ison=false;
		ths.hidden=false;
		ths.config = $config;		

		if( $config.id ){
			ths.element_id = ths.config.id;
			ths.element = $("#"+ths.element_id);
		}
		else{
			ths.element = $config.element;
		}
				
		ths.element.onclick=function(){
			if( ths.enabled && !ths.ison ){
				if( ths.onclick ) ths.onclick();
			}
		}
	}
	/*
	ths.on = function(){
		if( !ths.ison ){
			ths.ison=true;
			addClass(ths.element, "on");
			addClass(ths.arrow, "hide");
			ths.clock.on();
		}
	}
	ths.off = function(){
		if( ths.ison ){	
			ths.ison=false;	
			removeClass(ths.element, "on");	
			removeClass(ths.arrow, "hide");
			ths.clock.off();
		}
	}
	ths.disable = function(){
		if( ths.enabled ){
			ths.enabled=false;
			addClass(ths.element, "disable");
		}
	}
	ths.enable = function(){
		if( !ths.enabled ){
			ths.enabled=true;
			removeClass(ths.element, "disable");
		}
	}
	*/
	ths.hide = function(){
		if( !ths.hidden ){
			ths.hidden=true;
			addClass(ths.element, "hide");
		}
	}
	ths.show = function(){
		if( ths.hidden ){
			ths.hidden=false;
			removeClass(ths.element, "hide");
		}
	}
	ths.dispose = function(){
		if( ths.inited ){
		}
		ths.inited=false;
	}
}

function clock(){
	var ths = this;
	var config;
	var element_id;
	var element;
	var interval;
	var counter;
	var ticks;
	var inited;
	var ison;
	ths.init = function($config){
		ths.config = $config;
		ths.ison=false;	
		ths.ticks=9;		
		if( $config.id ){
			ths.element_id = ths.config.id;
			ths.element = $("#"+ths.element_id);
		}
		else{
			ths.element = $config.element;
		}
		ths.inited=true;
	}
	ths.on = function(){
		if(!ths.ison){
			ths.ison = true;
			ths.counter=0;
			ths.interval = setInterval(ths.update,94);
			ths.update();
		}
	}
	ths.off = function(){
		if(ths.ison){
			ths.ison = false;
			clearInterval(ths.interval);
			removeClass(ths.element, "icon-clock_"+ths.counter);
		}
	}
	ths.update = function(){
		removeClass(ths.element, "icon-clock_"+ths.counter);
		ths.counter++;
		if( ths.counter == ths.ticks ) ths.counter=0;
		addClass(ths.element, "icon-clock_"+ths.counter);
	}
	ths.dispose = function(){
		if( ths.inited ){
			clearInterval(ths.interval);
		}
		ths.inited=false;
	}
}

/* /////////////////////////////////////////////////////////////////////// DROPDOWN */
function dropdown(){		//$maxVisible optional

	var ths = this;
	var config;
	var element_id;
	var element;
	var opened;
	var current;
	var hitarea;
	
	var list;
	var list_origY;
	var scroller; 
	
	var inited;
	var needsScrollbar;
	var maxVisible;
	var dragging;
	var dragger;
	
	var totH;		// total height of scrolling list
	var listH;		// visible height of scrolling list
	var itemH;		// height on 1 item in the list
	var scrollerH;	// height of scrollarea
	var dragH;		// height of dragger
	var defaultTitle;
	
	var over;
	
	//Events
	var onChange;
	var onOpen;
	var onClose;
	
	ths.init = function($config)
	{
		ths.config = $config;
		
		if( ths.config.id ){
			ths.element_id = ths.config.id;
			ths.element = $("#"+ths.element_id);
		}
		else{
			ths.element = ths.config.element;
		}
		
		//------------------------------- mouseover / mouseout
		ths.element.onmouseout = function(){
			ths.over = false;
			proto.wait("wait_"+ths.element.id, {duration:20, func:ths.closeDropdown});
		}
		ths.element.onmouseover = function(){
			ths.over = true;
			proto.disposeWait("wait_"+ths.element.id);
		}
	
		ths.opened = false;
		ths.current = $(".current", ths.element)[0];
		ths.hitarea = $(".hitarea", ths.element)[0];
		
		ths.hitarea.onclick = function(){
			if(ths.opened)	ths.closeDropdown();
			else				ths.openDropdown();
		}
		
		ths.list = $(".list ul", ths.element)[0];
		ths.list_origY = getCss(ths.list, "top");
		ths.scroller = $(".scrollbar", ths.element)[0]; 
		
		ths.inited = false;
		ths.needsScrollbar = null;
		ths.maxVisible = ths.config.maxVisible;
		ths.dragging = false;
		ths.dragger;
		
		ths.totH;		// total height of scrolling list
		ths.listH;		// visible height of scrolling list
		ths.itemH;		// height on 1 item in the list
		ths.scrollerH;	// height of scrollarea
		ths.dragH;		// height of dragger
		ths.defaultTitle = $(".text", ths.current)[0].innerHTML;
		
		ths.over = false;
	
		//------------------------------- init
		ths.items = $("ul li", ths.element);
		for(var i=0; i<ths.items.length; i++){
			ths.items[i].onselectstart = function(){ return false };
			ths.items[i].onmouseup = function(){ ths.clickItem(this); }
		}
	}
	
	ths.openDropdown = function(){
		
		if(!ths.opened){
			
			ths.opened = true;
			
			//set z-index
			if(window["__highestDepth"] != undefined){
				window["__highestDepth"]++;
			} else {
				window["__highestDepth"] = 100;
			}
			setCss(ths.element, "z-index", window["__highestDepth"]);
			
			removeClass(ths.element, "closed");
			addClass(ths.element, "opened");
			
			// init once:	
			if(!ths.inited){
				ths.totH = getCss($("ul", ths.element)[0], "height");
				if(ths.maxVisible)		ths.checkScrollNeed();
				else							ths.listH  = ths.totH;
				
				if(agent.mobile){
					setCss(ths.list, "overflow", "scroll");
					addEvent(ths.list, "touchmove", function(){
						var btmY = ths.list_origY-(ths.totH-ths.listH);
						var perc = -getCss(ths.list, "scrollTop") / btmY
						ths.dragger.setPosition({y:perc});
					});
				}
				
				ths.inited = true;
			}
			
			if(ths.needsScrollbar)	ths.showScrollbar();
			
			if(!agent.mobile)		proto.tween(ths.list, {prop:"height", start:0, end:ths.listH, duration:5, skip:0.75});
			else						setCss(ths.list, "height", ths.listH);
			
			ths.element.focus();
			ths.element.onblur = function(){
				if(document.activeElement != ths.hitarea)	ths.closeDropdown();
				document.activeElement.onblur = null;
			}
			//ON OPEN
			if(ths.onOpen)ths.onOpen();	
		}
	}
	
	ths.closeDropdown = function(){
		if(ths.opened){
			if(!ths.dragging){
				ths.opened = false;
				addClass(ths.element, "closed");
				removeClass(ths.element, "opened");
				
				// scrollbar:
				if(ths.needsScrollbar)	ths.hideScrollbar();
			}else{
				ths.onStopDrag_fc = ths.closeDropdown;
			}
			
			//ON CLOSE
			if(ths.onClose)ths.onClose();
		}
	}
	
	
	//------------------------------- check if scrollbar needed:
	ths.checkScrollNeed = function(){
		var drag_mc = $(".drag", ths.scroller)[0];
		ths.dragH = getCss(drag_mc,"height");
		ths.itemH = getCss($("ul li", ths.element)[0], "scrollHeight");
		
		ths.listH = ths.itemH *ths.maxVisible;
		ths.scrollerH = ths.listH -ths.dragH -4;
		
		// scrollbar needed?
		if(ths.listH <ths.totH){
			setCss(ths.scroller, "height", ths.scrollerH+ths.dragH);
			ths.needsScrollbar = true;
		}else{
			ths.needsScrollbar = false;
			ths.listH = ths.totH;
		}
		
		// dragger:
		ths.dragger = new Dragger(drag_mc, {minX:0,maxX:0, minY:0,maxY:ths.scrollerH, moveElement:true})
		
		ths.dragger.onStartDrag = function(){
			ths.dragging = true;
		}
		
		ths.dragger.onStopDrag = function(){
			ths.dragging = false;
			if(ths.onStopDrag_fc){
				if(!ths.over)	ths.onStopDrag_fc();
				ths.onStopDrag_fc = null;
			}
		}
		
		ths.dragger.onMouseMove = function($x, $y){
			var perc = map($y, this.config.minY, this.config.maxY, 0, 1);
			setCss(ths.list, "top", ths.list_origY-(ths.totH-ths.listH)*perc);
		}
		
		// mousewheel: (see Class below)
		addMousewheelListener(ths.element, function($val){
			var currY = getCss(ths.list, "top");
			
			var topY = ths.list_origY;
			var btmY = ths.list_origY-(ths.totH-ths.listH);
			
			if($val >0)		var pos = currY+ths.itemH;
			else				var pos = currY-ths.itemH;
			pos = Math.max(Math.min(pos,topY), btmY);
			
			setCss(ths.list, "top", pos);
			
			ths.dragger.setPosition({y:pos/btmY});
		}, true);
	}
	
	
	//------------------------------- show / hide scrollbar	
	ths.showScrollbar = function(){
		setCss(ths.scroller, "display", "block");
	}
	
	ths.hideScrollbar = function(){
		setCss(ths.scroller, "display", "none");
	}
	
	//------------------------------- click items
	ths.clickItem = function($item){
		ths.activeItem($item);
		if(ths.onChange) ths.onChange();
	}
	
	ths.activeItem = function($item){
		document.activeElement.onblur = null;	
		var act = $("li.active", ths.element)[0];
		if(act)	removeClass(act, "active");
		addClass($item, "active");
		ths.setTitle($("p", $item)[0].innerHTML);
		ths.closeDropdown();
	}
	
	//------------------------------- set title
	ths.setTitle = function($title){
		$(".text", ths.current)[0].innerHTML = $title;
	}

	//------------------------------- get/setValue
	ths.getValue = function(){
		var active = $("li.active", ths.element)[0];
		if(active)	return active.getAttribute("value");
		else			return null;
	}
	ths.setValue = function($id){
		var items = $("li", ths.element);
		for(var i=0; i<items.length; i++){
			if($id === items[i].getAttribute("value")){
				ths.activeItem(items[i]);
				break;
			}
		}
	}
	ths.getText = function(){
		var active = $("li.active p", ths.element)[0];
		if(active)	return active.innerHTML;
		else			return null;
	}
	ths.reset = function(){
		var active = $("li.active", ths.element)[0];
		if(active){
			removeClass(active, "active");
			ths.setTitle(ths.defaultTitle);
		}
	}
}


/* /////////////////////////////////////////////////////////////////////// RADIO */
function radio_list(){		//$maxVisible optional
	
	var ths = this;
	var config;
	var element_id;
	var element;
	var ison = false;
	var hidden=false;

	var onShow;
	var onHide;

	ths.init = function($config)
	{
		ths.config = $config;
		
		if( ths.config.id ){
			ths.element_id = ths.config.id;
			ths.element = $("#"+ths.element_id);
		}
		else{
			ths.element = ths.config.element;
		}	
		
		ths.ison = false;
		ths.hidden=false;
		
		//------------------------------- init
		ths.items = $("ul li", ths.element);
		for(var i=0; i<ths.items.length; i++){
			ths.items[i].onselectstart = function(){ return false };
			ths.items[i].onmouseup = function(){ ths.clickItem(this); }
		}
	}
	
	ths.show = function(){
		if(ths.hidden){
			ths.hidden = false;
			removeClass(ths.element, "hide");
			addClass(ths.element, "show");
			
			if( ths.onShow) ths.onShow();
		}
	}
	ths.hide = function(){
		if(!ths.hidden){
			ths.hidden = true;
			removeClass(ths.element, "show");
			addClass(ths.element, "hide");
			
			if( ths.onHide) ths.onHide();
		}
	}
	
	ths.clickItem = function($item){
		document.activeElement.onblur = null;
		var active = $("li.active", ths.element)[0];
		if(active)	removeClass(active, "active");
		addClass($item, "active");
	}
	
	//------------------------------- get/setValue
	ths.getValue = function(){
		var active = $("li.active", ths.element)[0];
		if(active)	return active.getAttribute("value");
		else			return null;
	}
	ths.setValue = function($id){
		var items = $("li", ths.elem);
		for(var i=0; i<items.length; i++){
			if($id === items[i].getAttribute("value")){
				ths.clickItem(items[i]);
				break;
			}
		}
	}
	ths.getText = function(){
		var active = $("li.active p", ths.element)[0];
		if(active)	return active.innerHTML;
		else			return null;
	}
	ths.reset = function(){
		var active = $("li.active", ths.element)[0];
		if(active){
			removeClass(active, "active");
		}
	}
}